package com.woniuxy.job;

import com.woniuxy.pojo.MerchantCommission;
import com.woniuxy.pojo.OverOrder;
import com.woniuxy.pojo.PreOrder;
import com.woniuxy.service.CommissionjobService;
import com.woniuxy.service.impl.CommissionjobImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class Commissionjob {
    @Autowired
    private CommissionjobService commissionjobService;

    /**
     * 每十秒钟将 预订单和超时订单的数据读到 提成订单
     */
    //@Scheduled(cron = "0/10 * * * * ?")
    public  void doCommissionjob(){
        //查询所有preorder
      List<PreOrder> preOrders=commissionjobService.findAllpreorder();
      //查询所有 overorder
        List<OverOrder> overOrders=commissionjobService.findAlloverOrder();
        System.out.println(overOrders);
        for (PreOrder preOrder : preOrders) {
            MerchantCommission   merchantCommission=new MerchantCommission();
            merchantCommission.setOrderid(preOrder.getId()+"");
            merchantCommission.setPcid(preOrder.getPuId());
            merchantCommission.setLocation(preOrder.getLocation());
            for (OverOrder overOrder : overOrders) {
                if (overOrder.getOrderId()==preOrder.getId()){
                    Integer c =preOrder.getMoney();
                    BigDecimal item=new BigDecimal(c);
                   BigDecimal z =overOrder.getOverPrice().add(item);
                   merchantCommission.setCommission(z);
                }else {
                    Integer c =preOrder.getMoney();
                    BigDecimal item=new BigDecimal(c);
                    merchantCommission.setCommission(item);
                }
            }
            commissionjobService.updata(merchantCommission);
        }
    }

}
